package com.service;

import com.bean.Student;
import com.bean.Teacher;
import com.bean.User;
import com.dao.UserDao;
import org.apache.commons.collections4.CollectionUtils;
import org.python.antlr.ast.List;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Ming on 2016/9/14.
 */
@Service
public class LoginService {
    //从LoginController中传送过来的用户名和密码用下面的方法进行查找，返回布尔型的值
    @Autowired
    private UserDao userDao;

    public User getUsernameAndPass(User user){
        java.util.List<User> users=userDao.getUserByUsernameAndPass(user);
        if (CollectionUtils.isNotEmpty(users)){
            return users.get(0);
        }
        return null;
    }
    public Student getStudentByUsernameAndPass(Student student){
        java.util.List<Student> users=userDao.getStudentByUsernameAndPass(student);
        if (CollectionUtils.isNotEmpty(users)){
            return users.get(0);
        }
        return null;
    }
    public Teacher getTeacherByUsernameAndPass(Teacher teacher){
        java.util.List<Teacher> users=userDao.getTeacherByUsernameAndPass(teacher);
        if (CollectionUtils.isNotEmpty(users)){
            return users.get(0);
        }
        return null;
    }
    //查询用户id
    public java.util.List<User> getIdByUserName(String userName){
        java.util.List<User> id = userDao.getIdByUserName(userName);
        return id;
    }
}
